import request from '@/router/axios';

/**
 * 用户列表
 * @param current
 * @param size
 * @param params
 */
export const getList = (current, size, params) => {
  return request({
    url: '/user/user/page',
    method: 'POST',
    params: {
      ...params,
      current,
      size,
    }
  })
}

//唯一性校验
export const verifyUnique = (data) => request({
  url: '/user/user/verifyUnique',
  method: 'post',
  params: data
})

/**
 * 用户树
 * @param id
 */
export const userTree = (userId, regionId) => {
  return request({
    url: '/user/user/userTree',
    method: 'post',
    data: {
      "userId": userId,
      "regionId": regionId
    }
  })
}

/**
 * 用户新增
 * @param row
 */
export const add = (row) => {
  return request({
    url: '/user/user/add',
    method: 'post',
    data: row
  })
}

/**
 * 用户详情
 * @param row
 */
export const detail = (row) => {
  return request({
    url: '/user/user/detail',
    method: 'post',
    data: row
  })
}

/**
 * 用户详情
 * @param row
 */
export const userDetail = (row) => {
  return request({
    url: '/user/user/detail',
    method: 'post',
    data: row
  })
}

/**
 * 用户更新
 * @param row
 */
export const update = (row) => {
  return request({
    url: '/user/user/update',
    method: 'post',
    data: row
  })
}

/**
 * 重置密码
 * @param row
 */
export const reset = (row) => {
  return request({
    url: '/user/user/reset',
    method: 'post',
    data: row
  })
}

/**
 * 全部角色树
 */
export const grantRole = () => {
  return request({
    url: '/application/role/grantRole',
    method: 'get'
  })
}

/**
 * 获取已配置的用户角色
 * @param userIds
 */
export const userRole = (userIds) => {
  return request({
    url: '/user/user/userRole',
    method: 'get',
    params: {
      userIds,
    }
  })
}

/**
 * 配置用户角色权限
 * @param userIds
 * @param roleIds
 */
export const grant = (userIds, roleIds) => {
  return request({
    url: '/user/user/grant',
    method: 'post',
    data: {
      "userIds": userIds,
      "roleIds": roleIds
    }
  })
}

/**
 * 获取用户头像
 * @param userId
 */
export const avatar = (userId) => {
  return request({
    url: '/user/user/avatar',
    method: 'get',
    params: {
      userId,
    }
  })
}

export const uploadImage = (row) => {
  return request({
    url: '/user/user/upload',
    method: 'post',
    data: row
  })
}